﻿	<%@ taglib prefix='c' uri='http://java.sun.com/jsp/jstl/core'%>
	<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
	<%@ page import="com.cxx.purchasecharge.component.utils.ComponentConstants" %>
	
	<style type="text/css">
		#dlg-log input, #dlg-log select
		{
			width: 150px;
		}
		#dlg-log #fm-log div 
		{
			float: left;
			width: 300px;
		}
		#dlg-log #fm-log div label
		{
			width: 80px;
		}
	</style>
	
	<script type="text/javascript">
		var viewLogDetail = function () 
		{
			var row = $('#dg-log').datagrid('getSelected');
			if (row) {
				$('#dlg-log').dialog('open').dialog('setTitle', '查看日志详情');
				loadGridData ('#dg-logContent', '<c:url value='/log/getLogContents.html' />', {logId : row.id});
			}
		}
		var logTypeFormatter = function(value,row,index) 
		{
			if(value == 'LOGIN') 
			{
				return '登入';
			}
			if(value == 'LOGOUT') 
			{
				return '登出';
			}
			if(value == 'INSERT') 
			{
				return '插入';
			}
			if(value == 'UPDATE') 
			{
				return '更新';
			}
			if(value == 'DELETE') 
			{
				return '删除';
			}
		}
		var onClickUser = function() 
		{
			$(this).combobox('reload', '<c:url value='/user/getAllUser.html' />');
		}
		
		$(function() {$('#toolbar-log #searchLogByAdvance #logType').combobox('setValue', '');});
		var onSearchLogByAdvance = function () 
		{
			var startDate = $('#toolbar-log #searchLogByAdvance #startDate').combo('getValue');
			var endDate = $('#toolbar-log #searchLogByAdvance #endDate').combo('getValue');
			var logType = $('#toolbar-log #searchLogByAdvance #logType').combo('getValue');
			var userId = $('#toolbar-log #searchLogByAdvance #userId').combo('getValue');
			if((startDate != '' && endDate == '') || (startDate == '' && endDate != '')) 
			{
				$.messager.alert('警告','开始时间和结束时间必须同时填!','warning');
				return;
			}
			if(startDate == '' && endDate == '' && logType == '' && userId == '') 
			{
				$.messager.alert('警告','请填写查询条件!','warning');
				return;
			}
			var pageOptions = $('#dg-log').datagrid('getPager').data("pagination").options;
			var page = pageOptions.pageNumber;
			var rows = pageOptions.pageSize;
			loadGridData ('#dg-log', '<c:url value='/log/getLogs.html' />', {page:page, rows:rows, sort:'date', order:'desc', startDate:startDate, endDate:endDate, logType:logType, userId:userId});
		}
    </script>

	<div style="width:100%; height:450px;">
		<table id="dg-log" title="<spring:message code="log.logManagement" />" class="easyui-datagrid" url="<c:url value='/log/getLogs.html' />"
			toolbar="#toolbar-log" pagination="true" rownumbers="true" fit="true"
			 singleSelect="true" checkOnSelect="true" selectOnCheck="false"
			fitColumns="true" sortName="dateTime" sortOrder="desc">
			<thead>
				<tr>
					<th data-options="field:'ck',checkbox:true"></th>
					<th data-options="field:'id',hidden:true"></th>
					<th data-options="field:'type',width:50, sortable:true, formatter:logTypeFormatter">操作类型</th>
					<th data-options="field:'userId',width:50, sortable:true">用户</th>
					<th data-options="field:'tableId',width:50, sortable:true">表ID</th>
					<th data-options="field:'tableName',width:50, sortable:true">表名</th>
					<th data-options="field:'<%=ComponentConstants.LOG_DATE_TIME %>',width:100, sortable:true">日期</th>
					<th data-options="field:'comment',width:100">备注</th>
				</tr>
			</thead>
		</table>
	</div>
	<div id="toolbar-log" style="padding:5px;height:auto">
		<div>
			<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" 
				onclick="destroyMultipleModel('#dg-log', '<spring:message code="log.log" />', '<c:url value='/log/delLog.html' />')" title="<spring:message code="checkOneOrMultiple" />删除日志">删除日志</a>
			<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" plain="true" 
				onclick="viewLogDetail()" title="<spring:message code="selectOneRow" />查看日志详情">查看日志详情</a>
		</div>
		<div id="searchLogByAdvance" style="margin-left: 6px;">
			时间:<input id="startDate" name="startDate" class="easyui-datebox" style="width:100px" 
				editable="false" title="开始时间" data-options="">
				- <input id="endDate" name="endDate" class="easyui-datebox" style="width:100px" 
				editable="false" title="结束时间" data-options="">&nbsp;
		   	 操作类型: 
            <select id="logType" name="logType" class="easyui-combobox" panelHeight="auto" style="width:80px" editable="false">
                <option value="LOGIN">登入</option>
                <option value="LOGOUT">登出</option>
                <option value="INSERT">插入</option>
                <option value="UPDATE">更新</option>
                <option value="DELETE">删除</option>
            </select>&nbsp;
			用户: 
            <input id="userId" name="userId" class="easyui-combobox" style="width:100px" data-options="valueField:'userId',
											textField:'userId',
											url:'',
											mode:'local',
											filter:comboboxFilter,
											onShowPanel:onClickUser"/>
            <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" plain="true" title="查询" onclick="onSearchLogByAdvance()">查询</a>
        </div>
	</div>

	<div id="dlg-log" class="easyui-dialog"
		style="width: 750px; height: 390px; padding: 5px;" closed="true"
		buttons="#dlg-buttons-log" data-options="modal:true">
		<div id="" style="margin-top: 5px;">
			<table id="dg-logContent" class="easyui-datagrid"
				style="width: 700px; height: auto" url="" rownumbers="true"
				singleSelect="true" fitColumns="true">
				<thead>
					<tr>
						<th data-options="field:'id',hidden:true"></th>
						<th field="field" width="50">字段名</th>
						<th field="comment" width="50">字段类型</th>
						<th field="oldValue" width="100">旧值</th>
						<th field="newValue" width="100">新值</th>
					</tr>
				</thead>
			</table>
		</div>
	</div>
	<div id="dlg-buttons-log">
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-cancel" onclick="javascript:$('#dlg-log').dialog('close')"><spring:message code="close" /></a>
	</div>